/*
** cmd_monitor.c for zappy in /home/Smaxo/Travail/zappy-2015-2014s-renard_g/serv-src
**
** Made by maximilien addari
** Login   <addari_m@epitech.net>
**
** Started on  Fri Jun 22 15:24:37 2012 maximilien addari
** Last update Sun Jul 15 21:46:52 2012 maximilien addari
*/

#include		<unistd.h>
#include		<stdio.h>
#include		<stdlib.h>
#include		<string.h>

#include		"server.h"

static void		make_cmd(t_client *client, t_game *game, int x, int y)
{
  client->send->concat(client->send, "bct ");
  client->send->concat_value(client->send, x);
  client->send->concat(client->send, " ");
  client->send->concat_value(client->send, y);
  client->send->concat(client->send, " ");
  client->send->concat_value(client->send, game->obj[x][y].inv[FOOD]);
  client->send->concat(client->send, " ");
  client->send->concat_value(client->send, game->obj[x][y].inv[LINEMATE]);
  client->send->concat(client->send, " ");
  client->send->concat_value(client->send, game->obj[x][y].inv[DERAUMERE]);
  client->send->concat(client->send, " ");
  client->send->concat_value(client->send, game->obj[x][y].inv[SIBUR]);
  client->send->concat(client->send, " ");
  client->send->concat_value(client->send, game->obj[x][y].inv[MENDIANE]);
  client->send->concat(client->send, " ");
  client->send->concat_value(client->send, game->obj[x][y].inv[PHIRAS]);
  client->send->concat(client->send, " ");
  client->send->concat_value(client->send, game->obj[x][y].inv[THYSTAME]);
  client->send->concat(client->send, "\n");
}

void			bct(t_client *client, t_game *game, char *cmd)
{
  char			*token;
  unsigned int		x;
  unsigned int		y;

  x = game->coord.x;
  y = game->coord.y;
  token = strtok(cmd, " ");
  if ((token = strtok(NULL, " ")) != NULL)
    x = atoi(token);
  if ((token = strtok(NULL, "\n")) != NULL)
    y = atoi(token);
  if (x < game->coord.x && y < game->coord.y)
    make_cmd(client, game, x, y);
  else
    client->send->concat(client->send, "sbp\n");
}

void			mct(t_client *client, t_game *game, char *cmd)
{
  unsigned int		x;
  unsigned int		y;

  x = 0;
  (void)cmd;
  while (x < game->coord.x)
    {
      y = 0;
      while (y < game->coord.y)
	{
	  make_cmd(client, game, x, y);
	  y++;
	}
      x++;
    }
}

void			pin(t_client *client, t_game *game, char *cmd)
{
  int			*id;
  char			*token;

  (void)client;
  id = xmalloc(sizeof(int));
  *id = 0;
  token = strtok(cmd, " ");
  if ((token = strtok(NULL, " ")) != NULL)
    *id = atoi(token);
  game->event_mnt->add_back(game->event_mnt, new_event(INVENT_MNT, 0, id));
}

void			plv(t_client *client, t_game *game, char *cmd)
{
  int			*id;
  char			*token;

  (void)client;
  id = xmalloc(sizeof(int));
  *id = 0;
  token = strtok(cmd, " ");
  if ((token = strtok(NULL, " ")) != NULL)
    *id = atoi(token);
  game->event_mnt->add_back(game->event_mnt, new_event(LEVEL_MNT, 0, id));
}
